<template>
  <div>
    <a-form :model="form" layout="vertical" @submit-success="submit">
      <a-card :bordered="false">
        <a-form-item :label="t['字段名称']">
          <a-input v-model="form.fieldName"></a-input>
        </a-form-item>
        <a-form-item :label="t['字段类型']">
          <a-radio-group
            v-model="form.fieldType"
            :options="translateOptions(filedOptions)"
          ></a-radio-group>
        </a-form-item>
        <a-button :loading="loading" long type="primary" html-type="submit">
          {{ t["确定"] }}
        </a-button>
      </a-card>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { addField, updateField } from "@/api/service/field/field";

import { list } from "../data/curd";
import { form, showForm } from "../data/form";
import { filedOptions } from "../data/options";

const t = translate("公共模块");
const loading = ref(false);
const submit = async () => {
  loading.value = true;
  if (!form.value.fieldId) {
    await addField(form.value);
  } else {
    await updateField(form.value);
  }
  loading.value = false;
  list();
  showForm.value = false;
};
</script>

<style lang="scss" scoped></style>
